<?
session_start();
if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code']))) 
{
	// Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
	unset($_SESSION['security_code']);
	@mysql_connect("localhost","root","") or die("Khong the connect server");
	mysql_select_db("phimsot") or die("Khong ton tai database nay!");
	mysql_query("set names 'utf8'");
	if(isset($_POST['contact_name']))
		$prefix="contact";
	else $prefix="request";
	$validate=mysql_query("select * from thongtinlienhe where email='{$_POST[$prefix.'_email']}' and dienthoai='{$_POST[$prefix.'_phone']}'");
	if(mysql_num_rows($validate)==NULL)
	{
		if(mysql_query("insert into thongtinlienhe values ('','{$_POST[$prefix.'_name']}','$prefix','{$_POST[$prefix.'_email']}','{$_POST[$prefix.'_message']}','{$_POST[$prefix.'_phone']}',0)"))
		{
			header("location:../index.php?key=form");
		}
		else echo "insert into thongtinlienhe values ('','{$_POST[$prefix.'_name']}','$prefix','{$_POST[$prefix.'_email']}','{$_POST[$prefix.'_message']}','{$_POST[$prefix.'_phone']}')"; //header("location:../index.php?key=form_failed");
	}
	else header("location:../index.php?key=form_failed");
} else {
	header("location:../index.php?key=form_failed");
}
?>